//
//  NETWorkTool.m
//  quickDoctor
//
//  Created by zhaowei on 17/3/8.
//  Copyright © 2017年 SWS. All rights reserved.
//

#import "NETWorkTool.h"

@implementation NETWorkTool

//单例
+ (instancetype)sharedTool {
    
    static NETWorkTool *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance =[self manager];
    });
    return instance;
}

- (void)GETWithUrlStr:(NSString *)urlStr parameters:(id)parameters success:(void (^)(id))successBlock failure:(void (^)(NSError *))failureBlock {
    
    [self GET:urlStr parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        // 把AFN获取的responseObject,回调给外界
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];

}
- (void)POSTWithUrlStr:(NSString *)urlStr parameters:(id)parameters success:(void (^)(id))successBlock failure:(void (^)(NSError *))failureBlock {
    
    [self POST:urlStr parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        NSLog(@"%@",uploadProgress);
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        // 把AFN获取的responseObject,回调给外界
        if (successBlock) {
            successBlock(responseObject);
        }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }

    }];
}



@end
